package br.com.rglariguet.rgportal.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import br.com.rglariguet.rgportal.PermissaoAcesso;
import br.com.rglariguet.rgportal.dao.PermissaoDAO;

@Repository
@Transactional
public class PermissaoDAOImpl implements PermissaoDAO {

	private final SessionFactory factory;
	
	@Autowired
	public PermissaoDAOImpl (SessionFactory factory){
		this.factory = factory;
	}
	
	private Session getSession() {
		return factory.getCurrentSession();
	}

	@Override
	public PermissaoAcesso salvar(PermissaoAcesso permissao) {
		getSession().save(permissao);
		return permissao;
	}
	
	@Override
	public List<PermissaoAcesso> listarPermissoes() {
		return (List<PermissaoAcesso>)getSession().createQuery("from PermissaoAcesso").list();
	}

	@Override
	public PermissaoAcesso buscarPorId(Long id) {
		return (PermissaoAcesso) getSession().get(PermissaoAcesso.class, id);
	}
	
	
}
